<template>
    <div class="accountinfo-box" v-if="isShow">
        <p class="userBox">请检视您以下的账户信息</p>
        <table class="t_list" border="0" cellpadding="0" cellspacing="1">
            <tr>
                <td class="t_td_caption_1">账户</td>
                <td class="t_td_text">{{infoData.name}}</td>
            </tr>
            <tr>
                <td class="t_td_caption_1">盘口</td>
                <td class="t_td_text">{{pan}}盘</td>
            </tr>
            <tr>
                <td class="t_td_caption_1">{{infoData.deal_type == 1? '现金余额':'信用余额'}}</td>
                <td class="t_td_text">{{current.toFixed(2)}}<button class="refresh" @click="refresh">刷新</button></td>
            </tr>
        </table>
    </div>
</template>
<script>
    var timer = null;
    export default {
        name: "Accountinfo",
        props: {  //普通类型：String、Number、Boolean、Null    引用类型： Array、Object
            openBet: {  //可下注
                type: Boolean,
                required: true
            },
            ninetime: {  //90s
                type: Number,
                required: true
            },
            refreshaccount: {
                type: Number,
                required: true
            },
        },
        data(){
            return{
                infoData: {},
                pan: '',  //盘口
                current: '',
                lock: '',
                isShow: false,
            }
        },
        methods: {
            inits(){

                var _this = this;
                
                if(window.localStorage.Authorization){

                    if (timer) {
                        clearInterval(timer);
                        timer = null;
                    }

                    _this.$httpGet('/api/account/credit').then(response => {
                        
                        if(response.status == 200){

                            //判断 信用账户与现金账户
                            _this.pan = window.localStorage.pan;
                            _this.infoData.name = window.localStorage.accountname;
                            _this.infoData.deal_type = window.localStorage.deal_type;

                            if(window.localStorage.deal_type == 1){  //现金

                                _this.current = response.data.cash;

                            }else if(window.localStorage.deal_type == 2){  //信用

                                _this.current = response.data.quick;

                            }
                            _this.isShow = true;

                            timer = setInterval(() => {
                                _this.inits();
                            }, 10 * 1000)
                            
                        }

                    });
                    
                    
                }
                
            },
            refreshinits(){

                var _this = this;
                if(window.localStorage.Authorization){

                    this.$httpGet('/api/account/credit').then(response => {
                        
                        if(response.status == 200){
                            
                            //判断 信用账户与现金账户
                                _this.pan = window.localStorage.pan;
                                _this.infoData.name = window.localStorage.accountname;
                                _this.infoData.deal_type = window.localStorage.deal_type;

                                if(window.localStorage.deal_type == 1){  //现金

                                    _this.current = response.data.cash;

                                }else if(window.localStorage.deal_type == 2){  //信用

                                    _this.current = response.data.quick;

                                }
                                _this.isShow = true;
                        }

                    });
                }
                
            },
            //刷新
            refresh(){
                this.refreshinits();  //账户信息
                this.$emit('refresh');
            },
            
        },
        mounted(){
            this.inits();
        },
        beforeDestroy(){
            clearInterval(timer);
        },
        watch: {
            openBet: function(now,old){
                // console.log(now,old);
                //开奖  刷新路珠数据
                this.refreshinits();
                
            },
            ninetime: function(now,old){
                console.log('------------90s  账户信息');
                //90s  刷新数据
                this.refreshinits();
            },
            refreshaccount: function(now,old){
                console.log('------------下完注  刷新账户信息');
                //下完注  刷新数据
                this.refreshinits();
            },

        },
    }
</script>
